<template>
	<view>
			<van-cell-group>
				<van-field
				label="账户"
					:value="loginForm.account"
					placeholder="请输入账户"
					required
					clearable
					@change="accountChange"
				/>
				<van-field
				label="密码"
					:value="loginForm.password"
					placeholder="请输入密码"
					type="password"
					required
					clearable
					@change="passwordChange"
				/>
				
			</van-cell-group>
			<view class="action">
				<van-button type="primary" @click="handleLogin">登录</van-button>
				<van-button type="info" @click="handleRegister">注册</van-button>
			</view>
		
	</view>
</template>

<script lang="ts" setup>
import { loginUser } from '@/api/user';
import { reactive } from 'vue';
	
	const loginForm = reactive<any>({})
	const handleLogin = async ()=>{
		console.log('login....',loginForm);
		const {result} =   await loginUser(loginForm)
		const {token,userId} = result
		// console.log('token',token);
		uni.setStorageSync('Authorization',token)
		uni.setStorageSync('userId',userId)
		uni.redirectTo({url:'/pages/index/index'})
	}
	const handleRegister = ()=>{
		uni.redirectTo({url:'/pages/register/register'})
		console.log('register...');
	}
	const accountChange = (e:any)=>{
		loginForm.account = e.detail
	}
	const passwordChange = (e:any)=>{
		loginForm.password = e.detail
	}
</script>

<style>
.action{
	display: flex;
	justify-content: space-around;
}

</style>
